<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path ;
    request.setAttribute("basePath",basePath);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
        <title>设置资源</title>
        <%@include file="../../common/include_list_head.jsp" %>
        <!--树 start-->
        <link rel="stylesheet" href="${basePath}/component/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
        <script type="text/javascript" src="${basePath}/component/zTree/js/jquery.ztree.core-3.5.min.js"></script>
        <script type="text/javascript" src="${basePath}/component/zTree/js/jquery.ztree.excheck-3.5.min.js"></script>
        <!--树 end-->
        <!----信息提示start--->
        <link rel="stylesheet" href="${basePath}/component/msgbox/msgbox.css" type="text/css">
        <script type="text/javascript" src="${basePath}/component/msgbox/msgbox.js"></script>
        <!----信息提示end--->

        <SCRIPT type="text/javascript">
            <!--
            var setting = {
                check: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                }
            };

            var saveFlag = false;       //保存是否成功标记 成功点关闭则刷新界面
            var zNodes = ${zyTreeJsonData};
            var code;

            $(document).ready(function(){
                $.fn.zTree.init($("#treeDemo"), setting, zNodes);
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo");

                var selectedZY = $("#selectedZY").val();

                var array = selectedZY.split("|");      //选择指定的内容
                if(array!=null&&array.length>0){
                    for(var i=0;i<array.length;i++){
                        var nodeid = array[i];
                        if(nodeid!=""){
                            var node = treeObj.getNodeByParam("id", array[i], null);
                            treeObj.checkNode(node, true, true);
                        }
                    }
                }
            });

            function szzySave(){
                var url = "${basePath}"+"/business/regulation-szzySave.action";
                var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
                var nodes = treeObj.getCheckedNodes(true);
                var selectedZYValue = "";
                if(nodes!=null&&nodes!=""){
                    for(var i = 0;i<nodes.length;i++){
                        var node = nodes[i];
                        if(!node.isParent){     //保存不包含父节点
                            console.debug(node);
                            var nodeid = node['id'];
                            selectedZYValue += nodeid + "|";
                        }
                    }
                }

                var gzwidValue = document.getElementById("gzwid").value;
                $.post(url,
                        {
                            gzwid:gzwidValue,
                            selectedZY: selectedZYValue,
                            time: (new Date()).valueOf()
                        },
                        function (data) {
                            if("ok"!=data){
                                alert(data);
                                return false;
                            }else{
                                saveFlag = true;
                                $.msgbox.show({
                                    message: '保存成功！',
                                    icon: 'ok',
                                    timeOut: 1000
                                });
                                //alert("保存成功！");
                                return true;
                            }
                        });
            }
            //保存关刷新
            function closeAndRefresh(){
                if(saveFlag){
                    var rightFrm = parent.document.getElementById("frmright");
                    rightFrm.src =  "${basePath}" +"/business/regulation-list.action";
                }
                top.Dialog.close();
            }
            //-->
        </SCRIPT>

        <style type="text/css">
            html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, font, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td {
                margin: 0;padding: 0;border: 0;outline: 0;font-weight: inherit;font-style: inherit;font-size: 100%;font-family: inherit;vertical-align: baseline;}
            div.content_wrap {width: 600px;height:380px;margin: auto}
            div.zTreeDemoBackground {width:350px;height:362px;text-align:left;}

            ul.ztree {margin-top: 2px;margin-left:-2px;border: 1px solid #617775;background: #f0f6e4;width:582px;height:360px;overflow-y:scroll;overflow-x:auto;}

            ul.log li {color: #666666;list-style: none;padding-left: 10px;}

        </style>

	</head>

	<body style="overflow-x:hidden;overflow-y: hidden">
        <s:if test="actionErrors.size()>0 || actionMessages.size()>0 || fieldErrors.size()>0">
            <div id="SystemErrorMessage">
                <s:actionerror/>
                <s:actionmessage/>
                <s:fielderror/>
            </div>
        </s:if>

        <s:hidden name="gzwid" id="gzwid"/>
        <s:hidden name="selectedZY" id="selectedZY"/>

        <div class="content_wrap">
            <div class="zTreeDemoBackground">
                <ul id="treeDemo" class="ztree"></ul>
            </div>
        </div>

        <div style="float: right;margin-right: 5px;">
            <button onclick="szzySave()"><span class="icon_save">保存</span></button> <button onclick="closeAndRefresh()"><span class="icon_no">关闭</span></button>
        </div>


	</body>
</html>
